<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">

<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Project，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="project_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/project-list/1/1/20',
					  method:'get',
					  toolbar:'#tb',
					  loadMsg : '数据加载中',
					  onDblClickRow:onDblClickRow,
                   onRowContextMenu: onRowContextMenu,
                   onLoadSuccess:function(data){
                            $('.ok').linkbutton({plain:true,iconCls:'icon-ok'});
                            $('.uuid').linkbutton({plain:true,iconCls:'icon-new'});
                    },
					  showFooter: true" >
        <thead>
            <tr>
                <th data-options="field:'proLixiangFlag',width:40,align:'center',formatter:info "></th>
                <th data-options="field:'uuid',width:40,align:'center',formatter:uuidfile"></th>
                <th data-options="field:'userId',width:100,align:'center' ,formatter:userIdFormatter">业务人员</th>
                <th data-options="field:'proId',width:150,align:'center' ">项目编号</th>
                <th data-options="field:'proName',width:200,align:'center' ">项目名称</th>
                <th data-options="field:'proManager',width:200,align:'center' ">项目负责人</th>
                <th data-options="field:'proApprovalTime',width:200,align:'center' ">立项时间</th>
            </tr>
        </thead>
	</table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
    <div>
        项目名称:
        <input class="easyui-textbox" name="proName"id="proName">
        项目编号:
        <input class="easyui-textbox" name="proId"id="proId">
        项目负责人:
        <input class="easyui-textbox" name="proManager"id="proManager">
        <#--立项时间:-->
        <#--<input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="proApprovalTime" style="width:120px">-->

        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin-top: 5px">
      <#include "/common/button.html">
    </div>
</div>

<!-- 右键 -->
<div id="right_click" class="easyui-menu" style="width:120px;">
    <div onclick="nx()" data-options="iconCls:'icon-add'">决策</div>
    <div onclick="yc('N')" data-options="iconCls:'icon-cancel'">异常</div>
    <div onclick="yc('Y')" data-options="iconCls:'icon-cancel'">否决</div>
    <div class="menu-sep"></div>
    <div onclick="ed()" data-options="iconCls:'icon-edit'">编辑</div>
    <div onclick="query()" data-options="iconCls:'icon-add'">查看</div>
    <div onclick="up()" data-options="iconCls:'icon-upload'">上传</div>
    <div onclick="projectExport()" data-options="iconCls:'icon-upload'">导出</div>
</div>


<!-- 格式化时间 -->
<script type="text/javascript">
    function dateformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }
    function dateparser(s){
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }
</script>
<!-- 条件查询 -->
<script type="text/javascript">
    $("#searchByParameter").click(function(){
        var proId = $("#proId").val();
        var proName = $("#proName").val();
        var proManager = $("#proManager").val();
        //var proApprovalTime = $("#proApprovalTime").val();
        var handler = '/project-list/1/1/20?proId='+proId+"&proName="+proName+"&proManager="+proManager;
        $('#project_table').datagrid('options').url = handler;
        $('#project_table').datagrid('reload');
    });
</script>
<script type="text/javascript">

    function cellStyler(value,row,index){
        if (value == 1){
            return 'background-color:#ffee00;color:red;';
        }
    }

    function info(value) {
        var button = '';
        if(value==1){
            button += '<a href="#" class="ok" title="信息已经完善"></a>';
        }
        return button;
    }
    function uuidfile(value){
        var result = '';
        $.ajax({
            url : '/project-has-file/'+value+'/LX',
            async : false,
            success :function (data) {
                result = data;
            }
        })
        var button = '';
        if(result){
            button += '<a href="#" class="uuid" title="文件已经上传" onclick="uidFile(\''+value+'\')"></a>';
        }
        return button;
    }
    function uidFile(value){
        var url = '/project-files-show/'+value+'/LX';
        var index = layer.open({
            title: false,
            type: 2,
            area: ['900px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
    }

    function userIdFormatter(val){
        var result = '';
        $.ajax({
            url : '/user-get/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
</script>



<!-- 按钮操作 -->
<script type="text/javascript">
	$('#export').click(function(){
        window.location = "/project-download/1";
    });

    function projectExport() {
        var node = $('#project_table').datagrid('getSelected');
        if(null != node && "" != node){
            var id = node.id;
            var url = '/projectInfo-validate/'+id;
            var index = layer.open({
                title:'项目明细',
                type: 2,
                area: ['700px', '450px'],
                fixed: true, //不固定
                maxmin: true,
                content: url
            });
            layer.full(index);
        }else {
            layer.msg("请选择数据！");
        }
    }
</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#project_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
                var proId = $("#proId").val();
                var proName = $("#proName").val();
                var proManager = $("#proManager").val();
				var handler = '/project-list/1/'+pageNumber+"/"+pageSize+"?proId="+proId+"&proName="+proName+"&proManager="+proManager;
				$('#project_table').datagrid('options').url = handler;
				$('#project_table').datagrid('reload');
			}
		});
	})
</script>

<!-- 右键操作 -->
<script>
    function onRowContextMenu(e,row){
        e.preventDefault();
        var node = $('#project_table').datagrid('getSelected');
        if(node){
            $('#right_click').menu('show',{
                left: e.pageX,
                top: e.pageY
            });
        }
    }

    function onDblClickRow(rowIndex,rowData){
        var id = rowData.id;
        var title = rowData.proName;
        var url = '/project-lixiang-view/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    };

    function yc(val){
        var ycOrVeto = '';
        if(val == 'N'){
            ycOrVeto = '此项目被标记为异常，请描述异常原因';
        }else {
            ycOrVeto = '此项目被否决，请描述否决原因';
        }
        layer.prompt({title: ycOrVeto, formType: 2}, function(text, index){
            layer.close(index);
            var node = $('#project_table').datagrid('getSelected');
            $.ajax({
                type :'post',
                url : '/errorproject-set/'+val+'/'+node.id+'/',
                data : {reason:text,state:'立项阶段'},
                async :false,
                success :function(){
                    var handler = '/project-list/1/'+1+"/"+20;
                    $('#project_table').datagrid('options').url = handler;
                    $('#project_table').datagrid('reload');
                }
            });
        });
    }

    function nx(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/project-ruku-validate/'+id+'/1';
        var index = layer.open({
            title:'项目立项信息明细',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);

    }
    function de(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var proName = node.proName;
        layer.confirm('确定删除该项目(项目名称：'+proName+')？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/project-ins-upd-del/'+id,
                data : {deleteFlag:'Y',tm : new Date().getTime()},
                async : false,
                success : function(){
                    $('#project_table').datagrid('reload');
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
    }
    function ed(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/project-lixiang-edit/'+id+'/0';
        var index = layer.open({
            title:'项目立项',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);
    }
    function query() {
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var title = node.proName;
        var url = '/project-lixiang-view/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    }
    function up(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/common-upload/'+id+'/1';
        var index = layer.open({
            title:'资料上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            end:function () {
                var handler = '/project-list/1/1/20';
                $('#project_table').datagrid('options').url = handler;
                $('#project_table').datagrid('reload');
            },
            content: url
        });
        layer.full(index);
    }
</script>